package com.qst.controller;

import com.qst.pojo.Employee;
import com.qst.pojo.Meeting;
import com.qst.service.NotificationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.text.ParseException;
import java.util.List;

/**
 * @author KungSu.
 * @create 2021-06-21 15:06
 */
@Controller
public class NotificationsController {
    @Autowired
    NotificationsService notificationsService;

    /**
     * 查询近七天我的所有会议
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/myMeeting")
    public String myMeeting(Model model, HttpSession session) throws ParseException {
        Employee employee = (Employee) session.getAttribute("curUser");
        List<Meeting> meetings = notificationsService.findmeeting(employee.getEmployeeId()) ;
        model.addAttribute("myMeeting",meetings);
        return  this.findCancelMeeting(model,session);

    }

    /**
     *查询已取消会议
     * @param model
     * @param session
     * @return
     */
    @RequestMapping("/findCancelMeeting")
    public String findCancelMeeting(Model model, HttpSession session){
        Employee employee = (Employee) session.getAttribute("curUser");
        List<Meeting> meetings = notificationsService.findCancelMeeting(employee.getEmployeeId());
        model.addAttribute("cancelMeetings",meetings);
        return "notifications";
    }

    /**
     * 取消会议
     * @return
     */
    @RequestMapping("/cancelMeeting")
    public String CancelMeeting(Model model, HttpSession session,Integer meetingid) throws ParseException {
        notificationsService.cancelMeeting(meetingid);
        return  this.myMeeting(model,session);
    }
    /**
     * 删除会议
     * @return
     */
    @RequestMapping("/delMeeting")
    public String delMeeting(Model model, HttpSession session,Integer meetingid) throws ParseException {
        notificationsService.delMeeting(meetingid);
        return  this.myMeeting(model,session);
    }
    @RequestMapping("/reMeeting")
    public String reMeeting(Model model, HttpSession session,Integer meetingid) throws ParseException {
        notificationsService.reMeeting(meetingid);

        return  this.myMeeting(model,session);
    }
}
